<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>test</title>
</head>

<body>
    <div class="container">
        <input id="document" type="file" />
        <div class="row" style="width: 100%;">
            <div class="span8">
                <div id="output" class="well"></div>
            </div>
        </div>
    </div>
    <div contenteditable class="text needsclick" id="content" :class="inputClassObj" @focus="getFocus" @blur="getBlur" style="-webkit-user-select:text" @input="changeVal">请输入文字<!-- {{placeholderText}} --></div>

    <script src="https://cdn.bootcss.com/mammoth/1.4.8/mammoth.browser.js"></script>
    <script type="text/javascript">
        document.getElementById("document")
            .addEventListener("change", readFileInputEventAsArrayBuffer, false);

        function displayResult(result) {
            let html = result.value;
            let newHTML = html.replace(//g, '')
            .replace('<h1>', '<h1 style="text-align: center;">')
            .replace(/<table>/g, '<table style="border-collapse: collapse;">')
            .replace(/<tr>/g, '<tr style="height: 30px;">')
            .replace(/<td>/g, '<td style="border: 1px solid pink;">')
            .replace(/<p>/g, '<p style="text-indent: 2em;">');
            document.getElementById("output").innerHTML = newHTML;
        }

        function readFileInputEventAsArrayBuffer(event) {
            var file = event.target.files[0];
            var reader = new FileReader();

            reader.onload = function (loadEvent) {
                var arrayBuffer = loadEvent.target.result;//arrayBuffer   
                debugger  
                mammoth.convertToHtml({ arrayBuffer: arrayBuffer })
                    .then(displayResult)
                    .done();
            };

            reader.readAsArrayBuffer(file);
        }
    </script>
</body>

</html>
